package x.zero.gen;

import org.beetl.core.Template;
import org.beetl.sql.gen.BaseProject;
import org.beetl.sql.gen.Entity;
import org.beetl.sql.gen.SourceConfig;
import org.beetl.sql.gen.simple.BaseTemplateSourceBuilder;

import java.io.Writer;

public class ZeroEntitySourceBuilder extends BaseTemplateSourceBuilder {
    /**
     * 指定模板的路径
     */
    public static  String pojoPath = "zero_pojo.btl";
    public static  String pojoAliasPath = "pojoAlias.btl";
    private boolean alias = false;


    public ZeroEntitySourceBuilder(String name) {
        super(name);
    }
    public ZeroEntitySourceBuilder() {
        super("entity");
    }


    @Override
    public void generate(BaseProject project, SourceConfig config, Entity entity) {

        Template template =groupTemplate.getTemplate(pojoPath);
        template.binding("attrs", entity.getList());
        template.binding("className", entity.getName());
        template.binding("table", entity.getTableName());
        if(!config.isIgnoreDbCatalog()){
            template.binding("catalog",entity.getCatalog());
        }

        template.binding("package", project.getBasePackage(this.name));
        template.binding("imports", entity.getImportPackage());
        template.binding("comment", entity.getComment());

        Writer writer = project.getWriterByName(this.name,entity.getName()+".java");

        template.renderTo(writer);



    }
}
